package com.BraveY.Demo04;

import java.util.Scanner;

public class Demo01 {
    public static void main(String[] args) {
        Scanner S = new Scanner(System.in);
        System.out.println("请输入一个字符串");
        String str = S.nextLine();
        char[] newStr = str.toCharArray();
        System.out.println("使用toCharArray打印您输入的字符串：");
        System.out.print("[");
        for (int i = 0; i < newStr.length; i++) {
            if (i == newStr.length - 1) {
                System.out.println(newStr[i] + "]");
            } else {
                System.out.print(newStr[i] + ",");
            }
        }
        System.out.println("谢谢使用！");
        char[] newStr2 = new char[str.length()];
        for (int i = 0; i < str.length(); i++) {
            newStr2[i] = str.charAt(i);
        }
        System.out.println("使用charAt打印您输入的字符串：");
        System.out.print("[");
        for (int i = 0; i < newStr2.length; i++) {
            if (i == newStr2.length - 1) {
                System.out.println(newStr2[i] + "]");
            } else {
                System.out.print(newStr2[i] + ",");
            }
        }
        System.out.println("谢谢使用！");
    }
}
